/*
 * © Copyright 2011 Romain Marteau, Matthieu Totet
 * 
 *    This file is part of VineaToum.
 *
 *    VineaToum is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VineaToum is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VineaToum.  If not, see <http://www.gnu.org/licenses/>.
 *    
 */

package org.vineatoum.business;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import org.vineatoum.business.abstraction.BusinessAbstract;
import org.vineatoum.utils.Address;
import org.vineatoum.utils.Image;
import org.vineatoum.view.utils.jtablecustom.OwnerTable;
import org.vineatoum.view.utils.jtablecustom.TableListener;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Exploitation extends BusinessAbstract {
	@XmlElement
	private String name = "";
	@XmlElement
	private Address address;
	@XmlElement
	private String legalForm;
	@XmlElement
	private String registrationNumber;
	@XmlElementWrapper(name = "owners")
	@XmlElement(name = "owner")
	private List<String> owners;
	@XmlElement
	private int numberOfEmployees;
	@XmlElement
	private Image logo;
	@XmlElementWrapper(name = "plantations")
	@XmlElement(name = "plantation")
	private List<Plantation> plantations;
	@XmlElementWrapper(name = "parcelles")
	@XmlElement(name = "parcelle")
	private List<Parcelle> parcelles;
	@XmlElementWrapper(name = "cuves")
	@XmlElement(name = "cuve")
	private List<Cuve> cuves;
	
	public Exploitation() {
		owners = new ArrayList<String>();
		plantations = new ArrayList<Plantation>();
		parcelles = new ArrayList<Parcelle>();
		cuves = new ArrayList<Cuve>();
		
		address = new Address();
		logo = new Image();
		
		owners.add("Otto Bus");
		owners.add("Otto Route");
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the address
	 */
	public Address getAddress() {
		return address;
	}
	/**
	 * @param address the address to set
	 */
	public void setAddress(Address address) {
		this.address = address;
	}
	/**
	 * @return the legalForm
	 */
	public String getLegalForm() {
		return legalForm;
	}
	/**
	 * @param legalForm the legalForm to set
	 */
	public void setLegalForm(String legalForm) {
		this.legalForm = legalForm;
	}
	/**
	 * @return the registrationNumber
	 */
	public String getRegistrationNumber() {
		return registrationNumber;
	}
	/**
	 * @param registrationNumber the registrationNumber to set
	 */
	public void setRegistrationNumber(String registrationNumber) {
		this.registrationNumber = registrationNumber;
	}
	/**
	 * @return the owners
	 */
	public List<String> getOwners() {
		return owners;
	}
	/**
	 * @param owners the owners to set
	 */
	public void setOwners(List<String> owners) {
		this.owners = owners;
	}
	/**
	 * @return the logo
	 */
	public Image getLogo() {
		return logo;
	}
	/**
	 * @param logo the logo to set
	 */
	public void setLogo(Image logo) {
		this.logo = logo;
	}
	/**
	 * @return the plantations
	 */
	public List<Plantation> getPlantations() {
		return plantations;
	}
	/**
	 * @param plantations the plantations to set
	 */
	public void setPlantations(List<Plantation> plantations) {
		this.plantations = plantations;
	}
	/**
	 * @return the parcelles
	 */
	public List<Parcelle> getParcelles() {
		return parcelles;
	}
	/**
	 * @param parcelles the parcelles to set
	 */
	public void setParcelles(List<Parcelle> parcelles) {
		this.parcelles = parcelles;
	}
	/**
	 * @param numberOfEmployees the numberOfEmployees to set
	 */
	public void setNumberOfEmployees(int numberOfEmployees) {
		this.numberOfEmployees = numberOfEmployees;
	}
	/**
	 * @return the numberOfEmployees
	 */
	public int getNumberOfEmployees() {
		return numberOfEmployees;
	}
	
	public void updateExploitation(Exploitation exploitationOld) {
		this.name = exploitationOld.name;
		this.address = exploitationOld.address;
		this.legalForm = exploitationOld.legalForm;
		this.registrationNumber = exploitationOld.registrationNumber;
		this.owners = exploitationOld.owners;
		this.numberOfEmployees = exploitationOld.numberOfEmployees;
		this.logo = exploitationOld.logo;
		this.plantations = exploitationOld.plantations;
		this.parcelles = exploitationOld.parcelles;
		this.cuves = exploitationOld.cuves;
	}
	
	public List<OwnerTable> getOwnersData() {
		List<OwnerTable> ret = new ArrayList<OwnerTable>(); 
		for (Iterator<String> iterator = owners.iterator(); iterator.hasNext();) {
			String ownerTable = (String) iterator.next();
			OwnerTable o = new OwnerTable(ownerTable);
			ret.add(o);
		}
		return ret;
	}
	
	public void setOwnersData(Vector<OwnerTable> data) {
		List<String> ret = new ArrayList<String>();
		for (Iterator<OwnerTable> iterator = data.iterator(); iterator.hasNext();) {
			OwnerTable ownerTable = (OwnerTable) iterator.next();
			ret.add(ownerTable.getName());
		}
		setOwners(ret);
	}
	public void setCuves(Vector<Cuve> data) {
		cuves = data;
	}
	public List<Cuve> getCuves() {
		return cuves;
	}
	@Override
	public TableListener getNewInstance() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public Vector<String> getVectorColumns() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public Vector<Object> getVectorData() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void updateField(String field, Object value) {
		// TODO Auto-generated method stub
		
	}
}
